package scau.hotel.hotel_web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import scau.hotel.hotel_service.entity.Checkout;
import scau.hotel.hotel_service.service.CheckoutService;
import scau.hotel.hotel_service.vo.CheckoutVo;
import scau.hotel.hotel_model.controller.RespBean;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Checkout)表控制层
 *
 * @author makejava
 * @since 2022-04-11 22:59:56
 */
@RestController
@PreAuthorize("hasAnyAuthority('admin','normal')")
@RequestMapping("checkout")
@Api(value = "typeApi", tags = "退房控制器")
public class CheckoutController {
    /**
     * 服务对象
     */
    @Resource
    private CheckoutService checkoutService;

    /**
     * 不分页查询
     *
     * @param checkout 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    @ApiOperation("不分页查询所有")
    public RespBean queryAll(Checkout checkout) {
        return RespBean.success(this.checkoutService.queryAll(checkout));
    }

    /**
     * 分页查询
     *
     * @param pageNum  起始页
     * @param pageSize 每页数据大小
     * @param checkout     筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    @ApiOperation("分页查询所有数据")
    public RespBean page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, Checkout checkout) {
        PageHelper.startPage(pageNum, pageSize);
        List<Checkout> list = checkoutService.queryAll(checkout);
        PageInfo<List> pageInfoA = new PageInfo(list);
        return RespBean.success(pageInfoA);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param checkoutId 主键
     * @return 单条数据
     */
    @GetMapping("{checkoutId}")
    @ApiOperation("根据id查询数据")
    public RespBean queryById(@PathVariable("checkoutId") Integer checkoutId) {
        return RespBean.success(this.checkoutService.queryById(checkoutId));
    }

    /**
     * 新增数据
     *
     * @param checkout 实体
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增一行数据")
    public RespBean add(@RequestBody Checkout checkout) {
        return this.checkoutService.insert(checkout);
    }

    /**
     * 编辑数据
     *
     * @param checkout 实体
     * @return 编辑结果
     */
    @PutMapping
    @ApiOperation("编辑数据")
    public RespBean edit(@RequestBody Checkout checkout) {
        return this.checkoutService.update(checkout);
    }

    /**
     * 删除数据
     *
     * @param checkoutId 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{checkoutId}")
    @ApiOperation("根据id删除数据")
    @PreAuthorize("hasAuthority('admin')")
    public RespBean deleteById(@PathVariable Integer checkoutId) {
        return RespBean.success(this.checkoutService.deleteById(checkoutId));
    }

    /**
     * 查询提示今天即将退房或超时未退房的订单明细
     *
     * @return 查询结果
     */
    @GetMapping("/todayCheckout")
    @ApiOperation("查询提示今天即将退房或超时未退房的订单明细")
    public RespBean queryTodayCheckout() {
        return RespBean.success(this.checkoutService.queryTodayCheckout());
    }

    /**
     * 返回需退房房间的入住人信息
     *
     * @return RespBean
     */
    @PostMapping("/returnCheckoutCus")
    @ApiOperation("返回需退房房间的入住人信息（需要入住明细id数组）")
    public RespBean returnCheckoutCus(@RequestBody List<String> checkinInforIds) {
        return this.checkoutService.returnCheckoutCus(checkinInforIds);
    }

    /**
     * 返回需退房房间的入住人信息
     *
     * @return RespBean
     */
    @PostMapping("/confirmCheckout")
    @ApiOperation("确认退房")
    public RespBean confirmCheckout(@RequestBody List<CheckoutVo> checkoutVoList) {
        return this.checkoutService.confirmCheckout(checkoutVoList);
    }
}

